{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 8 to 9"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In GDSFactory8, ports and instance units were not consistent with each other. Port units were in DBU while instance units were in um.\n",
    "\n",
    "GDSFactory9 makes ports and instance units consistent with each other. Port units are in um while instance units are in um.\n",
    "\n",
    "We have had to make some small changes to the API of the following classes:\n",
    "\n",
    "- Component\n",
    "- Port\n",
    "- ComponentReference\n",
    "- ComponentReferences"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Main changes\n",
    "\n",
    "Note the migration changes:\n",
    "- `port.dangle` has been renamed to `port.orientation`\n",
    "    - `port.angle` represents the angle 90 degrees multiples.\n",
    "    - `port.orientation` represents the angle in degrees.\n",
    "- `CHECK_INSTANCES` has been renamed to `CheckInstances`\n",
    "    - Most often used in the `@cell` decorator.\n",
    "- `Port(..., layer: tuple[int, int])` has been replaced with `Port(..., layer: int)`\n",
    "    - `layer` now represents the layer index in the KLayout layer stack.\n",
    "    - To update your code you can do `Port(..., layer=gf.kcl.layout.layer(*layer))`\n",
    "    - We also recommend just using Component.add_port, which lets you specify the layer as tuple.\n",
    "- Most of the `d` prefix attributes and functions can now be used without the `d` prefix.\n",
    "- `ComponentReference.parent` has been removed, you should use `ComponentReference.cell` instead.\n",
    "- `ComponentReference.info` has been removed, you should use `ComponentReference.cell.info` instead."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import gdsfactory as gf\n",
    "\n",
    "c = gf.components.straight(length=10)\n",
    "c.pprint_ports()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print('port orientation in degrees', c.ports['o2'].orientation)\n",
    "print('port x in um', c.ports['o2'].x)\n",
    "print('port dx in um (decimal)', c.ports['o2'].dx)\n",
    "print('port ix in integer (database units)', c.ports['o2'].ix)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c = gf.Component()\n",
    "ref = c << gf.c.straight()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ref.xmin = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print('reference x in um', ref.x)\n",
    "print('reference dx in um (decimal)', ref.dx)\n",
    "print('reference ix in integer (database units)', ref.ix)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
